﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//
using System.Web.Services;
using DDSC.OracleADO;
using System.Collections;
using System.Text;
using System.Data;

public partial class krj_tracking_shipping_loss : BasePermissionPage
{
    
    //搜尋SQL
    [WebMethod]
    public static Object GetLOSS(string RECEIVED_DEPT, string RECEIVED_DATE, PageInfo p_PageInfo)
    {
        Object results = new Object();
        try
        {
            dbAccess m_dba = new dbAccess();
            StringBuilder m_sb = new StringBuilder();
            ArrayList m_arrParam = new ArrayList();
            m_sb.Append(" select A.F60505 RECEIVED_DATE,F60504 || ' ' || C.DEPT_NAME DISPATCH_DEPT,F60501 DETAIL_NO, F60502 ITEM_NO,F60506 || ' ' || D.DEPT_NAME NOTICE_DEPT,F60510 LOSS_COUNT,F60507 SHIPPER,F60508 RECEIVER  ");
            m_sb.Append(" from as400_ZDF605 A ");
            m_sb.Append(" left join MIS_DEPT_AP C on A.F60504 = C.DEPT_ID ");
            m_sb.Append(" left join MIS_DEPT_AP D on A.F60506 = D.DEPT_ID ");
            //到著日期
            m_sb.Append(" AND F60505 >= :RECEIVED_DATE ");
            m_arrParam.Add(m_dba.GetOracleParam(":RECEIVED_DATE", RECEIVED_DATE));
            //到著所站
            m_sb.Append(" where F60506 =:RECEIVED_DEPT ");
            m_arrParam.Add(m_dba.GetOracleParam(":RECEIVED_DEPT", RECEIVED_DEPT));
           
            

            m_sb.Append(" AND F60521 = '50' ");

            results = ADOGridHandler(m_sb, m_arrParam, p_PageInfo);
            //20130628**********************************************
            //記錄最後查詢的條件
            krj_tracking_shipping_loss sa = new krj_tracking_shipping_loss();
            sa.savecondition( RECEIVED_DEPT,  RECEIVED_DATE);
        }
        catch (Exception ex)
        {
            BasePermissionPage BP = new BasePermissionPage();
            results = BP.BP_Message;
            BP.ERROR_DBSAVE("krj_tracking_shipping_loss.aspx.cs", "GetLOSS", ex.Message, "", "c#", "0", ex.StackTrace);
        }
        return (results);

    }
    

    protected void Page_Load(object sender, EventArgs e)
    {
        DataSet ds = null;
        try
        {
            ds = DBINT();
            if (ds.Tables[0].Rows[0]["ReturnCode"].ToString() == "000")
            {
                ddlRECEIVE_DEPT.DataTextField = "DEPT_NAME";
                ddlRECEIVE_DEPT.DataValueField = "DEPT_ID";
                ddlRECEIVE_DEPT.DataSource = ds.Tables["DEPT"];
                ddlRECEIVE_DEPT.DataBind();
            }
        }
        catch (Exception ex)
        {
           lbl_message.Text = BP_Message;
           ERROR_DBSAVE("krj_tracking_shipping_loss.aspx.cs", "Page_Load", ex.Message, "", "c#", "0", ex.StackTrace);
        }
    }
    
    protected DataSet DBINT()
    {
        DataSet ds = null;
        try
        {
            dbAccess m_dba = new dbAccess();
            StringBuilder m_sb = new StringBuilder();
            ArrayList m_arrParam = new ArrayList();

            m_sb.Append(" select A.bi4101 DEPT_ID ,A.bi4101 || '-' || B.DEPT_NAME DEPT_NAME ");
            m_sb.Append(" from as400_bif41 A left join MIS_DEPT_AP  B on A.BI4101 = B.DEPT_ID ");
            m_sb.Append(" where BI4121 = '1' and (BI4122 = '1' or BI4122 = '2') ");
            m_sb.Append(" order by A.bi4101 ");

            ds = m_dba.runExecuteQuery("DEPT", m_sb.ToString(), m_arrParam);
            //if (ds.Tables[0].Rows[0]["ReturnCode"].ToString() != "000")
            //{
            //    lbl_message.Text = "as400_bif41: 資料讀取錯誤！" + ds.Tables[0].Rows[0]["LogMessage"];
            //}

        }
        catch (Exception ex)
        {
            lbl_message.Text = BP_Message;
            ERROR_DBSAVE("krj_tracking_shipping_loss.aspx.cs", "DBINT", ex.Message, "", "c#", "0", ex.StackTrace);
        }
        return ds;
    }
    protected void btn_exist_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Default.aspx");
    }

    protected void savecondition(string RECEIVED_DEPT, string RECEIVED_DATE)
    {
        try
        {
            DropDownList ddl = new DropDownList();
            TextBox tx = new TextBox();

            var controlItem = new List<ControlItem>() 
            {
              new ControlItem("ddlRECEIVE_DEPT", RECEIVED_DEPT, ddl.GetType()),
              new ControlItem("txtRECEIVED_DATE", RECEIVED_DATE, tx.GetType()) 
              
            };
            ConditionRecordUtil.RecordSearchConditionData(controlItem);
        }
        catch (Exception ex)
        {
            ERROR_DBSAVE("krj_tracking_shipping_loss.aspx.cs", "savecondition", ex.Message, "", "c#", "0", ex.StackTrace);
        }
    }
}